package com.ruoyi.zhgd.controller;

import java.util.List;
import java.util.Arrays;
import java.util.Map;

import com.ruoyi.zhgd.domain.NWarningManagement;
import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckLogin;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.zhgd.domain.vo.NWarningManagementVo;
import com.ruoyi.zhgd.domain.bo.NWarningManagementBo;
import com.ruoyi.zhgd.service.INWarningManagementService;

/**
 * 报警管理
 *
 * @author cj
 * @date 2023-09-26
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/zhgd/warningManagement")
public class NWarningManagementController extends BaseController {

    private final INWarningManagementService iNWarningManagementService;

    /**
     * 查询报警管理列表
     */
    @SaCheckLogin
    @GetMapping("/list")
    public R list(@RequestParam Map<String, Object> params) {
        NWarningManagement map = iNWarningManagementService.queryPageList(params);
        return R.ok(map);
    }

    /**
     * 查询混凝土报警管理列表
     */
    @SaCheckLogin
    @GetMapping("/hntList")
    public R hntList(@RequestParam Map<String, Object> params) {
        List<NWarningManagement> list = iNWarningManagementService.queryHntList(params);
        return R.ok(list);
    }


    @SaCheckLogin
    @Log(title = "混凝土修改保存报警管理", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PostMapping("/updateHnt")
    public R updateHnt(@RequestBody List<NWarningManagement> management) {
        iNWarningManagementService.updateHnt(management);
        return R.ok();
    }

    @SaCheckLogin
    @Log(title = "报警管理", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping("/update")
    public R update(@RequestBody NWarningManagement management) {
        iNWarningManagementService.updatew(management);
        return R.ok();
    }



    /**
     * 导出报警管理列表
     */
    @SaCheckLogin
    @Log(title = "报警管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(NWarningManagementBo bo, HttpServletResponse response) {
        List<NWarningManagementVo> list = iNWarningManagementService.queryList(bo);
        ExcelUtil.exportExcel(list, "报警管理", NWarningManagementVo.class, response);
    }

    /**
     * 获取报警管理详细信息
     *
     * @param id 主键
     */
    @SaCheckLogin
    @GetMapping("/{id}")
    public R<NWarningManagementVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable String id) {
        return R.ok(iNWarningManagementService.queryById(id));
    }

    /**
     * 新增报警管理
     */
    @SaCheckLogin
    @Log(title = "报警管理", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody NWarningManagementBo bo) {
        return toAjax(iNWarningManagementService.insertByBo(bo));
    }

    /**
     * 修改报警管理
     */
    @SaCheckLogin
    @Log(title = "报警管理", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody NWarningManagementBo bo) {
        return toAjax(iNWarningManagementService.updateByBo(bo));
    }

    /**
     * 删除报警管理
     *
     * @param ids 主键串
     */
    @SaCheckLogin
    @Log(title = "报警管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable String[] ids) {
        return toAjax(iNWarningManagementService.deleteWithValidByIds(Arrays.asList(ids), true));
    }


    /**
     * 模拟采集数据接口
     * 张拉、压浆、压力机、万能机、混凝土分别对应code值为zl,yj,ylj,wnj,hnt;
     * @param code
     * @return
     */
    @SaCheckLogin
    @Log(title = "模拟采集数据接口")
    @GetMapping("/testCollectData")
    public R testCollectData(@RequestParam("code") String code,@RequestParam("deptId") String deptId) {
        if (code == null || code.length() == 0) {
            return R.fail("缺少参数code值");
        }
        iNWarningManagementService.testCollectData(code,deptId);
        return R.ok();
    }


}
